package com.boot.controller;

import com.alibaba.fastjson.JSON;
import com.boot.param.User;
import com.boot.validate.group.ValidateGroupNameTwo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author onlyone
 */
@Valid
@RestController
@RequestMapping("/test")
public class TestController {

    /**
     * 访问地址：http://localhost:8092/test/save_user
     */
    @RequestMapping(value = "/save_user", method = RequestMethod.POST)
    public String saveUser(@Valid User user) {

        // TODO 大量的业务处理

        return "保存用户成功！user= " + JSON.toJSONString(user);
    }

    /**
     * 注意：@Validated标记时，@Length没有生效，但分组生效了
     */
    @RequestMapping(value = "/save_user_2", method = RequestMethod.POST)
    public String saveUser2(@Validated(value = ValidateGroupNameTwo.class) User user) {

        // TODO 大量的业务处理

        return "保存用户成功！user= " + JSON.toJSONString(user);
    }
}
